home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 123 / cdrom123.iso / essenc / extens / imzoom / Image Zoom.xpi / chrome / imagezoom.jar / content / imageZoomOverlay.js < prev    next >
Encoding:
JavaScript  |  2004-08-18  |  5.2 KB  |  161 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  
  3.     Copyright (c) 2004  Jason Adams <jason_nospam@yellowgorilla.net>
  4.  
  5.     This file is part of Image Zoom.
  6.  
  7.     Image Zoom is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     Image Zoom is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with Image Zoom; if not, write to the Free Software
  19.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20.  
  21.  * ***** END LICENSE BLOCK ***** */
  22.  
  23. function retrieveImage()
  24. {
  25.     var oImage = document.popupNode;
  26.     return initImage(oImage);
  27.  
  28. }
  29.  
  30. function initImage(oImage)
  31. {
  32.     if (!(oImage.originalPxWidth))
  33.     {
  34.         if (!oImage.style.width && !oImage.style.height){
  35.             oImage.originalWidth = oImage.width;
  36.             oImage.originalPxWidth = oImage.width;
  37.             oImage.originalWidthUnit = "px";
  38.             oImage.widthUnit = "px";
  39.             oImage.style.width = oImage.width + oImage.widthUnit;
  40.             oImage.originalHeight = oImage.height;
  41.             oImage.originalHeightUnit = "px";
  42.             oImage.heightUnit = "px";
  43.             oImage.style.height = oImage.height + oImage.heightUnit;
  44.         } else if(oImage.style.width && !oImage.style.height){
  45.             oImage.originalWidth = getDimInt(oImage.style.width);
  46.             oImage.originalPxWidth = oImage.width;
  47.             oImage.originalWidthUnit =  getDimUnit(oImage.style.width);
  48.             oImage.widthUnit = oImage.originalWidthUnit;
  49.         } else if(oImage.style.height && !oImage.style.width){
  50.             oImage.originalHeight = getDimInt(oImage.style.height);
  51.             oImage.originalHeightUnit =  getDimUnit(oImage.style.height);
  52.             oImage.heightUnit = oImage.originalHeightUnit;
  53.             oImage.originalPxWidth = oImage.width;
  54.         } else if(oImage.style.width && oImage.style.height){
  55.             oImage.originalWidth = getDimInt(oImage.style.width);
  56.             oImage.originalPxWidth = oImage.width;
  57.             oImage.originalWidthUnit =  getDimUnit(oImage.style.width);
  58.             oImage.widthUnit = oImage.originalWidthUnit;
  59.             oImage.originalHeight = getDimInt(oImage.style.height);
  60.             oImage.originalHeightUnit =  getDimUnit(oImage.style.height);
  61.             oImage.heightUnit = oImage.originalHeightUnit;
  62.         }
  63.         oImage.zoomFactor = 100;
  64.  
  65.     }
  66.  
  67.     return oImage;
  68. }
  69.  
  70. function izShowCustomZoom()
  71. {
  72.     var oImage = retrieveImage();
  73.     openDialog("chrome://imagezoom/content/customzoom.xul", "", "chrome,modal,centerscreen", oImage);
  74.     zoomStatus(oImage);
  75. }
  76.  
  77. function izShowCustomDim()
  78. {
  79.     var oImage = retrieveImage();
  80.     openDialog("chrome://imagezoom/content/customdim.xul", "", "chrome,modal,centerscreen", oImage);
  81.     zoomStatus(oImage);
  82. }
  83.  
  84. function izImageFit(){
  85.  
  86.     var padValue = 17;
  87.     var oImage = retrieveImage();
  88.  
  89.     if (oImage.ownerDocument.compatMode == "BackCompat"){
  90.         var screenHeight = oImage.ownerDocument.body.clientHeight - padValue;
  91.         var screenWidth = oImage.ownerDocument.body.clientWidth - padValue;
  92.     } else {
  93.         var screenHeight = oImage.ownerDocument.documentElement.clientHeight - padValue;
  94.         var screenWidth = oImage.ownerDocument.documentElement.clientWidth - padValue;
  95.     }
  96.  
  97.     var screenDim = screenWidth/screenHeight;
  98.     var imageDim = oImage.width/oImage.height;
  99.  
  100.  
  101.     if (screenDim < imageDim) {
  102.         pSetDim(oImage, screenWidth, parseInt(screenWidth/imageDim+0.5), true);
  103.     } else {
  104.         pSetDim(oImage, parseInt(screenHeight*imageDim+0.5), screenHeight, true);
  105.     }
  106.  
  107.     if (oImage.ownerDocument.compatMode == "BackCompat"){
  108.         var screenHeight = oImage.ownerDocument.body.clientHeight - padValue;
  109.         var screenWidth = oImage.ownerDocument.body.clientWidth - padValue;
  110.     } else {
  111.         var screenHeight = oImage.ownerDocument.documentElement.clientHeight - padValue;
  112.         var screenWidth = oImage.ownerDocument.documentElement.clientWidth - padValue;
  113.     }
  114.  
  115.     if (screenDim < imageDim) {
  116.         pSetDim(oImage, screenWidth, parseInt(screenWidth/imageDim+0.5), true);
  117.     } else {
  118.         pSetDim(oImage, parseInt(screenHeight*imageDim+0.5), screenHeight, true);
  119.     }
  120.  
  121.     if (imagezoomPrefs.getBoolPref("autocenter")){
  122.         var iTop = 0;
  123.         var iLeft = 0;
  124.         var cNode = oImage;
  125.         while(cNode.tagName!='BODY'){
  126.            iLeft += cNode.offsetLeft;
  127.            iTop += cNode.offsetTop;
  128.            cNode = cNode.offsetParent;
  129.         }
  130.  
  131.         if (screenDim < imageDim) {
  132.             oImage.ownerDocument.defaultView.scroll(iLeft-(padValue/2),iTop-((screenHeight-getDimInt(oImage.style.height))/2)-(padValue/2));
  133.         } else {
  134.             oImage.ownerDocument.defaultView.scroll(iLeft-((screenWidth-getDimInt(oImage.style.width))/2)-(padValue/2),iTop-(padValue/2));
  135.         }
  136.     }
  137.     zoomStatus(oImage);
  138. }
  139.  
  140. function izZoomIn()
  141. {
  142.     var oImage = retrieveImage();
  143.     pZoomImageRel(oImage,(pGetZoomFactor()/100));
  144.     zoomStatus(oImage);
  145. }
  146.  
  147. function izZoomOut()
  148. {
  149.     var oImage = retrieveImage();
  150.     pZoomImageRel(oImage,1/(pGetZoomFactor()/100));
  151.     zoomStatus(oImage);
  152. }
  153.  
  154. function izSetZoom(zFactor)
  155. {
  156.     var oImage = retrieveImage();
  157.       pZoomImageAbs(oImage,zFactor);
  158.     zoomStatus(oImage);
  159. }
  160.  
  161.